﻿$(function () {
    ARegionWarehousePlan();
    BRegionWarehousePlan();
    CRegionWarehousePlan();
    DRegionWarehousePlan();
})
function ARegionWarehousePlan() {
    layui.use(function () {
        $.ajax({
            url: '/Warehouse/WarehousePlanShowMethod',
            type: 'get',
            data: {
                ReservoirArea:"A区域",
            },
            success: function (data) {
                data = JSON.parse(data);
                //console.log(data);
                $(data.data).each(function () {
                    $("#ARegionPlan").append(
                        '<div style = "background-color:white;width:145px;height:145px;float:left;margin:10px">'+
                            '<p>'+this.warehouseName+'</p>'+
                        '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="delWarehouse(' + this.warehouseId+')">删除</a>'+
                        '<a class="layui-btn layui-btn-Info layui-btn-xs" onclick="LookWarehouse(' + this.warehouseId +')">查看</a>'+
                        '</div> '
                    )
                })
            }
        });
    });
}

function BRegionWarehousePlan() {
    layui.use(function () {
        $.ajax({
            url: '/Warehouse/WarehousePlanShowMethod',
            type: 'get',
            data: {
                ReservoirArea: "B区域",
            },
            success: function (data) {
                data = JSON.parse(data);
                //console.log(data);
                $(data.data).each(function () {
                    $("#BRegionPlan").append(
                        '<div style = "background-color:white;width:145px;height:145px;float:left;margin:10px">' +
                        '<p>' + this.warehouseName + '</p>' +
                        '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="delWarehouse(' + this.warehouseId + ')">删除</a>' +
                        '<a class="layui-btn layui-btn-Info layui-btn-xs" onclick="LookWarehouse(' + this.warehouseId + ')">查看</a>' +
                        '</div> '
                    )
                })
            }
        });
    });
}
function CRegionWarehousePlan() {
    layui.use(function () {
        $.ajax({
            url: '/Warehouse/WarehousePlanShowMethod',
            type: 'get',
            data: {
                ReservoirArea: "C区域",
            },
            success: function (data) {
                data = JSON.parse(data);
                //console.log(data);
                $(data.data).each(function () {
                    $("#CRegionPlan").append(
                        '<div style = "background-color:white;width:145px;height:145px;float:left;margin:10px">' +
                        '<p>' + this.warehouseName + '</p>' +
                        '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="delWarehouse(' + this.warehouseId + ')">删除</a>' +
                        '<a class="layui-btn layui-btn-Info layui-btn-xs" onclick="LookWarehouse(' + this.warehouseId + ')">查看</a>' +
                        '</div> '
                    )
                })
            }
        });
    });
}
function DRegionWarehousePlan() {
    layui.use(function () {
        $.ajax({
            url: '/Warehouse/WarehousePlanShowMethod',
            type: 'get',
            data: {
                ReservoirArea: "D区域",
            },
            success: function (data) {
                data = JSON.parse(data);
                //console.log(data);
                $(data.data).each(function () {
                    $("#DRegionPlan").append(
                        '<div style = "background-color:white;width:145px;height:145px;float:left;margin:10px">' +
                        '<p>' + this.warehouseName + '</p>' +
                        '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="delWarehouse(' + this.warehouseId + ')">删除</a>' +
                        '<a class="layui-btn layui-btn-Info layui-btn-xs" onclick="LookWarehouse(' + this.warehouseId + ')">查看</a>' +
                        '</div> '
                    )
                })
            }
        });
    });
}
//删除仓库
function delWarehouse(warehouseId) {
    layer.confirm("确认要删除吗?", function (index) {
        console.log(warehouseId);
        $.ajax({
            type: 'post',
            url: '../Warehouse/DelWarehouse',
            data: {
                WarehouseId: warehouseId,
                token: localStorage.getItem("token")
            },
            success: function (res) {
                var obj = JSON.parse(res);
                if (obj.code === 0) {
                    layer.msg("删除成功");
                    Show();//重新加载显示
                }
                else {
                    layer.msg("删除失败");
                }
            },
            error: function (err) {
                layer.msg('删除失败，请稍后再试', {
                    time: 2000,
                    icon: 2
                })
            }
        })
        layer.close(index);
    })
}

//跳转仓库详情页
function LookWarehouse(warehouseId) {
    localStorage["warehouseId"] = warehouseId;
    location.href = "/Warehouse/WarehouseLook";
}